package com.walkline.weibo.dao;

import java.util.Date;
import net.rim.device.api.i18n.SimpleDateFormat;
import org.json.me.JSONObject;
import com.walkline.util.StringUtility;
import com.walkline.weibo.WeiboException;
import com.walkline.weibo.WeiboSDK;
import com.walkline.weibo.inf.Favorite;
import com.walkline.weibo.inf.Status;
import com.walkline.weibo.inf.TagWrapper;

public class WeiboFavorite extends WeiboObject implements Favorite
{
	private Date _favorited_at = new Date();
	private Status _status = null;
	private TagWrapper _tags = null;

	public WeiboFavorite(WeiboSDK weibo, JSONObject jsonObject)	throws WeiboException 
	{
		super(weibo, jsonObject);

		JSONObject favorite = jsonObject;
		if (favorite != null)
		{
			_favorited_at = StringUtility.parseDate(favorite.optString("favorited_time"));
			_status = new WeiboStatus(weibo, favorite.optJSONObject("status"));
			_tags = new WeiboTagWrapper(weibo, favorite.optJSONArray("tags"));
		}
	}

	public Status getStatus() {return _status;}

	public TagWrapper getTags() {return _tags;}

	public String getFavoriteTimeAtLong()
	{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");

		return sdf.formatLocal(_favorited_at.getTime());
	}

	public String getFavoriteTimeAtShort()
	{
		SimpleDateFormat sdf = new SimpleDateFormat("M/d HH:mm");

		return sdf.formatLocal(_favorited_at.getTime());
	}
}